package com.alibaba.controller;

import com.alibaba.annotation.SystemLog;
import com.alibaba.common.ResponseResult;
import com.alibaba.define.domain.UserDO;
import com.alibaba.define.domain.vo.BlogUserLoginVO;
import com.alibaba.define.domain.vo.UserInfoVO;
import com.alibaba.define.service.UserService;
import com.alibaba.define.service.request.RegisterRequest;
import com.alibaba.define.service.request.UpdateUserRequest;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author : hanyang
 * @date : 2023-11-03 09:11
 **/

@RestController
@Slf4j
public class UserController {

    @Resource
    UserService userService;

    @PostMapping("/login")
    @SystemLog(businessName = "用户登陆")
    public ResponseResult<BlogUserLoginVO> login(@RequestBody UserDO user) {
        log.info("UserController ==> login() request:{}", JSON.toJSONString(user));
        return userService.login(user);
    }

    @PostMapping("/logout")
    @SystemLog(businessName = "退出登陆")
    public ResponseResult<Void> logout() {
        log.info("UserController ==> logout()...");
        return userService.logout();
    }

    @GetMapping("/user/userInfo")
    @SystemLog(businessName = "查询用户信息")
    public ResponseResult<UserInfoVO> getUserInfo() {
        log.info("UserController ==> getUserInfo()...");
        return userService.getUserInfo();
    }

    @PutMapping("/user/userInfo")
    @SystemLog(businessName = "更新用户信息")
    public ResponseResult<Void> updateUserInfo(@RequestBody UpdateUserRequest request) {
        log.info("UserController ==> updateUserInfo() request:{}", JSON.toJSONString(request));
        return userService.updateUserInfo(request);
    }

    @PostMapping("/user/register")
    @SystemLog(businessName = "用户注册")
    public ResponseResult<Void> register(@RequestBody RegisterRequest request) {
        log.info("UserController ==> register() request:{}", JSON.toJSONString(request));
        return userService.register(request);
    }



}
